package leetcode.周赛.第276场;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/1/16 14:14
 * @description：https://leetcode-cn.com/problems/minimum-moves-to-reach-target-score/
 */
public class 得到目标值的最少行动次数 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.minMoves(5, 0));
    }
    class Solution {
        public int minMoves(int target, int maxDoubles) {
            int ans = 0;
            while (maxDoubles > 0) {
                if (target == 1) return ans;
                if (target % 2 == 0) {
                    target >>= 1;
                    maxDoubles--;
                } else {
                    target--;
                }
                ans++;
            }
            ans += target - 1;
            return ans;
        }
    }
}
